<?php

namespace Home\Controller;

use User\Api\UserApi;
use Think\Controller;
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');  
// 响应类型  
header('Access-Control-Allow-Methods:*');  
// 响应头设置  
header('Access-Control-Allow-Headers:x-requested-with,content-type');  
class IndexController extends Controller
{

    public function _initialize(){
        $_SERVER['SERVER_NAME'] ="app.xiaoyichuxing.net";
        I('get.id','1');
    }

    /**
     * 轮询查看订单状态
     * @order_id 订单编号
     */
    public function pay_status(){
        $order_id       = I('order_id');
        empty($order_id) && datamsg(0,'找不到该订单');
        $order  = D('xllog')->where(array('id'=>$order_id))->find();
        empty($order) && datamsg(0,'找不到该订单');
        if($order['pay_statu']==1){
            datamsg(1,'支付成功');
        }else{
            datamsg(0,'等待支付');
        }

    }
    /**
     * 撤销订单
     * @order_id 订单编号
     */
    public function cexiao(){
        if(IS_POST){
            $data       = I();
            empty($data['order_id']) && datamsg(0,'找不到该订单1');
            empty($data['name']) && datamsg(0,'请填写收款人姓名');
            empty($data['mobile']) && datamsg(0,'请填写手机号');
            empty($data['card']) && datamsg(0,'请填写银行卡号');

            if(!preg_match("/^1[34578]\d{9}$/", $data['mobile'])){
                datamsg(0,'请输入正确的手机号');
            }
            $order  = D('xllog')->where(array('id'=>$data['order_id']))->find();
            empty($order) && datamsg(0,'找不到该订单2');

            strlen($data['card']<10) && datamsg(0,'请输入正确的银行卡号');
            $info   = array(
                'name'      => $data['name'],
                'mobile'    => $data['mobile'],
                'card'      => $data['card'],
            );
            $save_info  =json_encode($info);

            D('xllog')->where(array('id'=>$data['order_id']))->save(array('status'=>7,'saveinfo'=>$save_info));
            datamsg(1,'提交成功');
        }else{
            $this->display('revocation');
        }

    }
    /**
     * 乘客支付页面
     * @order_id 订单编号
     */
    public function newPay(){
        $openid = session('openid');
        if(empty($openid)){
            header("location:/index.php?s=/Index/blogin");
        }

        import('Common.Wechat.Wechat');
        $map['id'] = 1;
        $config = M('User')->where($map)->find();
        $options = array(

            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $openid = session('openid');


        $maq['id'] = I('get.orderid');
        $order = M('xllog')->where($maq)->find();


        // echo 1;die;
        $mav['id'] = I('get.id');
        $shmc = M('User')->where($mav)->getfield('merchant');

        if ($order['pay_statu'] == 1){
            $png = '';
            $this->assign('paypng',$png);
        }else{
            $mobilepay = new MobilepayController();
            $png = $mobilepay->CCBmobilepay($order['price'],$order['orderid']);
            $this->assign('paypng',$png);
        }
        $evaluate = M('evaluates')->where(array('orderid'=>$order['orderid']))->find();
        if (empty($evaluate)){
            $this->assign('evaluate',$evaluate);
        }else{
            $this->assign('evaluate',$evaluate);
        }
        $this->assign('shmc', $shmc);
        $this->assign('order', $order);
        $this->assign('id', I('get.id'));
        $this->assign('orderid', I('get.orderid'));

        $this->display('newpay');
    }
    /**
     * 获取乘客点，下车点
     * @param id 路线id
     * @return josn
     */
    public function getEndPathyo(){
        !IS_POST && datamsg(0,'非法操作');
        $data = I();
        empty($data) && datamsg(0,'请先选择路线');
        $endPath=D('price')->where(array('from_city'=>$data['start']))->select();
        empty($endPath) && datamsg(0,'没有更多数据');
        datamsg(1,'成功',$endPath);
    }
    /**
     * 获取结束路线的地点
     * @param id 路线id
     * @return josn
     */
    public function getEndPath(){
        !IS_POST && datamsg(0,'非法操作');
        $id = I('id');
        empty($id) && datamsg(0,'请先选择路线');
        $endPath=D('price')->where(array('from_city'=>$id))->select();
        empty($endPath) && datamsg(0,'没有更多数据');
        datamsg(1,'成功',$endPath);
    }

    /**
     * 修改密码
     * @param mobile 手机号
     * @param password 新密码
     */
    public function up_pwd()
    {
        $mobile   = I("mobile");
        D('wxuser')->where(array('tel'=>$mobile))->save(array('password'=>md5('a1234567')));

        datamsg(1,'修改成功');
    }
    /**
     * 乘客注册
     * @param tel 手机号
     * @param verify 验证码
     * @param password 密码
     * @param repassword 确认密码
     */
    public function register()
    {
        if(IS_POST){
            $rules = array(
                array('tel','require','手机号必须！',1),
                array('verify','require','验证码必须！',1), //默认情况下用正则进行验证
                array('password','require','密码必须！',1),
                array('repassword','require','确认密码必须！',1),
                array('tel','','手机号已经存在！',0,'unique',1), // 在新增的时候验证name字段是否唯一
                array('repassword','password','确认密码不正确',0,'confirm',1) // 验证确认密码是否和密码一致
            );
            $password=I('password');
            if(!preg_match("/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/",$password)){
                datamsg(0,"密码必须包含数字和字母,密码长度不得低于8位");
            }

            $wxuser = M("wxuser");
            if (!$wxuser->validate($rules)->create()){
                datamsg(0,$wxuser->getError());
            }
            $mobile=I('tel');
            $verify=I('verify');


            $res= D("verify")->where("mobile=".$mobile)->order("id desc")->find();

            if ($res['random']!=$verify) {
                datamsg(0,'验证码输入错误！');
            }
            $time=$res['create_time']+180;

            if($time<time()){
                datamsg(0,'验证码已过期');
            }
            $User = new UserApi;
            $uid = $User->register_app($mobile,$password);
            if($uid<0){
                datamsg(0,$this->showRegError($uid));
            }
            $pho['mobiele']=$mobile;
            datamsg('1','注册成功',$pho);
        }else{

            $this->display();
        }
    }

    //未注册前的主页
    public function oindex()
    {
        if(!IS_POST)
        {
            datamsg(0,'非法操作');
        }
        $ico=D('article_type')->find('4');
      
        $list=D('article')->field('title,content')->where('type_id=4')->select();
        if(empty($list))
        {
            datamsg('1','暂无更多');
        }
        foreach ($list as $key => $value) {
            $list[$key]['create_time']=date('Y-m-d',$value['create_time']);
            $list[$key]['content']= htmlspecialchars_decode($value['content']);
        }
        $list['ico']=$_SERVER['SERVER_NAME'].$ico['ico'];

        datamsg('1','成功',$list);

    }

    //注册之后的主页
    public function hindex()
    {
        if(!IS_POST)
        {
            datamsg(0,'非法操作');
        }

        $user_id=I('user_id');
        $token=I('token');
        //今天订单金额
        $user=user_cinfo($user_id,$token);
        $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
        $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
        $data['today_sum']=D("xllog")->where('openid="'.$user['openid'].'" and (addtime>='.$beginToday.' and addtime<='.$endToday.')')->sum('price');
        $data['today_count']=D("xllog")->where('openid="'.$user['openid'].'" and (addtime>='.$beginToday.' and addtime<='.$endToday.')')->count('1');
        $data['integral']=$user['integral'];
        $data['status']=$user['status'];
        if($data['today_sum']==null)
        {
            $data['today_sum']=0;
        } 
        
        empty($data['today_count'])?0:$data['today_sum'];
        empty($data['integral'])?0:$data['today_sum'];
        
       
        $res['code']='1';
        $res['msg']="成功";
        $res['result']=$data;
        echo json_encode($res);

    }

    public function void()
    {
        // echo 1;die;
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        import('Common.Wechat.Wechat');
        $options = array(
            'token' => $config ["token"], // 填写你设定的key
            'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
        );
        // dump($options);die;
        $weObj = new \Common\Wechat\Wechat ($options);
        $weObj->valid();
        $type = $weObj->getRev()->getRevType();
        switch ($type) {
            case 'text':
            	$eventype = $weObj->getRev()->getRevContent();
            	$zdhf=M('zdhf')->where(array('keyword'=>$eventype))->find();
            	if($zdhf){
            		$weObj->text($zdhf['info'])->reply();
            	}else{
				$zdhf=M('zdhf')->where(array('keyword'=>0))->find();
                $weObj->text($zdhf['info'])->reply();}
                exit;
                break;
            case 'event':
                $eventype = $weObj->getRev()->getRevEvent();
                if ($eventype['event'] == "subscribe") {
                    $news = M("gzhf")->where(array("key" => "关注回复"))->select();
                    for ($i = 0; $i < count($news); $i++) {
                        if ($news[$i]["url"] == '') {
                            $url = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/gzhf");

                        } else {
                            $url = $news[$i]["url"] . '&uid=' . $weObj->getRevFrom();

                        }
                        $newsArr[$i] = array(
                            'Title' => $news[$i]["title"],
                            'Description' => $news[$i]["description"],
                            'PicUrl' => $news[$i]["picurl"],

                            'Url' => $url
                        );
                    }

                    $weObj->getRev()->news($newsArr)->reply();
                }
                exit;
                break;
            case 'image':
                $weObj->text("hello, I'm wechat")->reply();
                exit;
                break;
            case 'subscribe':
                //$weObj->text("关注事件")->reply();
                exit;
                break;
            default:
                $weObj->text("help info")->reply();
        }
    }

    public function ms_api()
    {

    }


    public function blogin(){
        // echo 2;die;
        $this->display();
    }

    public function doLogin(){
// echo 1;die;
        if (IS_POST) {
// echo I('post.code');die;
            $verify = new \Think\Verify();
            if ($verify->check(I('post.code'))) {
                $tel = I('tel');
                $apppwd = I('apppwd');
                $user = M('wxuser')->where(array('tel'=>$tel,'password'=>md5($apppwd)))->find();
                if($user){
                    session('openid',$user['openid']);
                    // echo session('openid');die;
                    echo 0;
                    
                }else{
                    echo 1;
                }
            }else{
                echo 3;
            }
        }
        
    }

    public function logOut(){
        session_destroy();
        session_unset();
        header("location: https://" . $_SERVER['HTTP_HOST']);

    }


    public function index()
    {
//            if(!I('get.zfs')){
//                $this->error('系统升级中！！！！');
//                exit();
//            }
// echo 1;die;
        $postStr = file_get_contents('php://input');
        $msg = array();
        if (!empty($postStr)) {
            $msg = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

             $this->orderquery($msg['out_trade_no']);
            $su = '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
            echo $su;

        }
//        if ($_POST) {
////            $this->orderquery($_POST['orderNo']);
////            $data['pay_statu'] = 1;
////            $data['order_statu'] = 1;
////            $mab['orderid'] = $_POST['orderNo'];
////            $data['orderno'] = $_POST['outOrderNo'];
////            $data['pay_time'] = $_POST['payTime'];
////            $data['transid'] = $_POST['transId'];
////            M('paylog')->where($mab)->save($data);
////            M('xllog')->where($mab)->save($data);
////            $id = M('paylog')->where($mab)->find();
////            $c_price = M('cz')->where(array('id' => $id['c_id']))->getField('free');
////            if ($id['tzzt'] == 0) {
////                //通知管理员
////                $this->sendtemplate($id['mid'], $_POST['orderNo'], $_POST['uuid']);
////                //通知用户
////                $this->tztemplate($_POST['orderNo'], 1, 3);
////                //通知司机
////                $this->sijitemplate($_POST['orderNo'], 1);
////                if (substr($_POST['orderNo'], 0, 2) == "H1") {
////
////                    $mae['openid'] = $_POST['uuid'];
////                    M('wxuser')->where($mae)->setinc('yue', (($_POST['amount'] / 100) + $c_price));
////                    $czdata['orderid'] = $_POST['orderNo'];
////                    $czdata['price'] = $_POST['amount'] / 100;
////                    $czdata['free'] = $c_price;
////                    $czdata['openid'] = $_POST['uuid'];
////                    $czdata['info'] = '充值' . $czdata['price'] . '送' . $c_price;
////                    $czdata['addtime'] = time();
////                    M('czlog')->add($czdata);
////                }
////                $da['tzzt'] = 1;
////
////                M('paylog')->where($mab)->save($da);
////
////
////            }

//        }
//        $postStr = file_get_contents('php://input');
//        if (!empty($postStr)) {
//            $msg = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
//            $pay_zt = $msg['return_code'];

//            if ($pay_zt == "SUCCESS") {
//
////                $data['pay_statu'] = 1;
////                $data['order_statu'] = 1;
////                $mab['orderid'] = $msg['out_trade_no'];
////                $data['orderno'] = $msg['transaction_id'];
////                $data['pay_time'] = $msg['time_end'];
////                $data['attach'] = $msg['attach'];
////                M('paylog')->where($mab)->save($data);
////                M('xllog')->where($mab)->save($data);
////                $id = M('paylog')->where($mab)->find();
////                $c_price = M('cz')->where(array('id' => $id['c_id']))->getField('free');
////                if ($id['tzzt'] == 0) {
////                    //通知管理员
////                    $this->sendtemplate($id['mid'], $msg['out_trade_no'], $msg['openid']);
////                    //通知用户
////                    $this->tztemplate($msg['out_trade_no'], 1, 3);
////                    //通知司机
////                    $this->sijitemplate($msg['out_trade_no'], 1);
////                    if (substr($msg['out_trade_no'], 0, 2) == "H1") {
////
////                        $mae['openid'] = $msg['openid'];
////                        M('wxuser')->where($mae)->setinc('yue', (($msg['total_fee'] / 100) + $c_price));
////                        $czdata['orderid'] = $msg['out_trade_no'];
////                        $czdata['price'] = $msg['total_fee'] / 100;
////                        $czdata['free'] = $c_price;
////                        $czdata['openid'] = $msg['openid'];
////                        $czdata['info'] = '充值' . $czdata['price'] . '送' . $c_price;
////                        $czdata['addtime'] = time();
////                        M('czlog')->add($czdata);
////                    }
////                    $da['tzzt'] = 1;
////
////                    M('paylog')->where($mab)->save($da);
////
////
////                }
//
//            }
//        }
        else {

          if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
                // echo 123456;die;
                $bis_weixin = 1;
                import('Common.Wechat.Wechat');
                $map['id'] = I('get.id');
                $config = M('User')->where()->find();
                $options = array(
                    'token' => "weilinzhou", // 填写你设定的key
                    'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
                    'appid' => $config['appid'], // 填写高级调用功能的app id
                    'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
                    'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
                );
                
                $weObj = new \Common\Wechat\Wechat ($options);
                $openid = session('openid');
                // echo $openid;die;
                // $_SERVER['SERVER_NAME'] ="xiaoyi.weixin88888888.com";
                if (strlen($openid) <= 10) {
                    $info = $weObj->getOauthAccessToken();
                    if (!$info) {
                        $callback = 'https://' . $_SERVER['SERVER_NAME'] . U("Index/index", array('id' => I('get.id')));
                        $url = $weObj->getOauthRedirect($callback, 'STATE');
                        // echo $callback;
                        // dump($url);die;
                        // echo $_SERVER['SERVER_NAME'];die;
                        header("Location: $url");
                        exit();
                    } else {
                        $openid = $info['openid'];
                        session('openid', $openid);
                    }
                }

            }else{
                $bis_weixin = 2;
            }
            $openid = session('openid');
            if(empty($openid)){
                // echo 1;die;
                $this->redirect("Index/blogin");
//                header("location:https://app.xiaoyichuxing.net/index.php?s=/Index/blogin");
                // echo 2;die;
            }else{
                $man['openid'] = $openid;
                $user = M('wxuser')->where($man)->find();
            }
           
            
            if (empty($user['openid'])) {
                if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
                    $info = $weObj->getUserInfo($openid);
                    $data['openid'] = $openid;
                    $data['nickname'] = json_encode($info['nickname']);
                    $data['headurl'] = $info['headimgurl'];
                    M("wxuser")->add($data);
                    header("location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
                }
            } else if (empty($user['tel'])) {
                $this->display('bangding');
            } else {
                // $info = $weObj->jsapi_ticket();
                // $timeStamp = time();
                // $nonce_str = $weObj->generateNonceStr();
                // $jsApiObj["timestamp"] = "$timeStamp";
                // $jsApiObj["noncestr"] = $nonce_str;
                // $jsApiObj['jsapi_ticket'] = $info;
                // $jsApiObj['url'] = 'https://' . $_SERVER ['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
                // $data["signature"] = $weObj->getSignature($jsApiObj);
                // $data["appid"] = $config['appid'];
// echo 1;die;
                $this->assign('data', $data);
                $this->assign('jsapi', $jsApiObj);
                if (I('get.dy') == 1) {
                    $this->assign('dy', 1);

                }
                session('form_city', null);
                session('end_city', null);
                session('start_x', null);
                session('end_x', null);
                session('start', null);
                session('end', null);


                $path_list  = D('price')->select();

                $this->assign('usertel', $user['tel']);
                $this->assign('path_list', $path_list);
                $this->assign('bis_weixin', $bis_weixin);
                $this->display();
            }
        }
    }


    public function pay()
    {


        import('Common.Wechat.Wechat');
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $openid = session('openid');
        if (strlen($openid) <= 10) {
            $info = $weObj->getOauthAccessToken();
            if (!$info) {
                $callback = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/pay", array('id' => I('get.id')));
                $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
                header("Location: $url");
                exit();
            } else {
                $openid = $info['openid'];
                session('openid', $openid);
            }
        }
        $mag['openid'] = $openid;
        $msp['orderid'] = I('get.orderid');
        $order = M('xllog')->where($msp)->find();

        if ($order['pay_statu'] != '1') {
            if (time() - $order['addtime'] > 700) {
                $this->error('订单超时');
                exit();

            }
            $yue = M('wxuser')->where($mag)->getfield('yue');
            $this->assign('order', $order);
            $this->assign('yue', $yue);
            $this->assign('price', $order['price']);
            $this->assign("headimg", $config['img']);
            $this->assign('shmc', $config['merchant']);
            $this->assign('id', I('get.id'));
            $this->assign('openid', $openid);
            $this->display();
        } else {

            $this->display('error');

        }
    }

    public function pay2()
    {

        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        import('Common.Wechat.Wechat');
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);

        $price = I('post.price');
        $appid = $config['appid'];
        $mch_id = $config['partnerid'];
        $out_trade_no = I('post.orderid');
        $body = "快捷支付";
        $sub_mch_id = $config['sub_mch_id'];
        $total_fee = $price * 100;
        $data['orderid'] = $out_trade_no;
        $data['mid'] = I('get.id');
        $data['openid'] = I('post.openid');
        $data['pay_statu'] = 0;
        $data['price'] = $price;
        $data['c_id'] = I('post.c_id');
        if (I('post.fs') == 'cz') {
            $data['attach'] = 'cz';
        } else {
            $data['attach'] = "预付款";
        }
        $data['add_time'] = time();
        $logs=M('paylog')->where(array('orderid'=>I('post.orderid')))->find();
        if(!$logs){
        $add = M('paylog')->add($data);}
        $openid = I('post.openid');
        $notify_url = 'https://' . $_SERVER ['SERVER_NAME'];
        $spbill_create_ip = $_SERVER["REMOTE_ADDR"];
        $nonce_str = $weObj->generateNonceStr();

        $pay_xml = $weObj->createPackageXml($appid, $mch_id, $sub_mch_id, $nonce_str, $body, $out_trade_no, $total_fee, $spbill_create_ip, $notify_url, $openid);

        $pay_xml = $weObj->get_pay_id($pay_xml);
//        file_put_contents('test.txt',$pay_xml,8);
        $prepay_id = $pay_xml['prepay_id'];
        $jsApiObj["appId"] = $appid;
        $timeStamp = time();
        $jsApiObj["timeStamp"] = "$timeStamp";
        $jsApiObj["nonceStr"] = $nonce_str;
        $jsApiObj["package"] = "prepay_id=" . $prepay_id;
        $jsApiObj["signType"] = "MD5";
        $jsApiObj["paySign"] = $weObj->getPaySignature($jsApiObj);

        $url = json_encode($jsApiObj);

        echo $url;

    }

//    public function orderquery($orderid)
//    {
//        $map['id'] = 1;
//        $config = M('User')->where($map)->find();
//        import('Common.Wechat.Wechat');
//        $options = array(
//            //'token' => $config ["token"], // 填写你设定的key
//            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
//            'appid' => $config['appid'], // 填写高级调用功能的app id
//            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
//            'partnerid' => $config['partnerid'], // 财付通商户身份标识
//            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
//            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
//        );
//        $weObj = new \Common\Wechat\Wechat ($options);
//        $param['merNo'] = $config['cmmb_mch_id'];
//        $param['orderNo'] = $orderid;
//        $param['signIn'] = $weObj->getcmmbpaysignature($param);
//        $sj = $weObj->getcmmborderquery($param);
//        $sj = json_decode($sj, true);;
//        if ($sj['result'] == "0000") {
//
//            $mbl['orderid'] = $sj['orderNo'];
//            $mbl['order_statu'] = 1;
//
//            $paystatu = M('paylog')->where($mbl)->find();
//            if ($paystatu['pay_statu'] == 0) {
//                $data['pay_statu'] = 1;
//                $data['order_statu'] = 1;
//
//                $mab['orderid'] = $sj['orderNo'];
//                $data['orderno'] = $sj['outOrderNo'];
//                $data['pay_time'] = $sj['payTime'];
//                $data['transid'] = $sj['transId'];
//                M('paylog')->where($mab)->save($data);
//                M('xllog')->where($mab)->save($data);
//                $id = M('paylog')->where($mab)->find();
//                $c_price = M('cz')->where(array('id' => $id['c_id']))->getField('free');
//                if ($id['tzzt'] == 0) {
//                    //通知管理员
//                    $this->sendtemplate($id['mid'], $sj['orderNo'], $sj['uuid']);
//                    //通知用户
//                    $this->tztemplate($sj['orderNo'], 1, 3);
//                    //通知司机
//                    $this->sijitemplate($sj['orderNo'], 1);
//                    if (substr($_POST['orderNo'], 0, 2) == "H1") {
//                        $mae['openid'] = $sj['uuid'];
//                        M('wxuser')->where($mae)->setinc('yue', (($sj['amount'] / 100) + $c_price));
//                        $czdata['orderid'] = $sj['orderNo'];
//                        $czdata['price'] = $sj['amount'] / 100;
//                        $czdata['free'] = $c_price;
//                        $czdata['openid'] = $sj['uuid'];
//                        $czdata['info'] = '充值' . $czdata['price'] . '送' . $c_price;
//                        $czdata['addtime'] = time();
//                        M('czlog')->add($czdata);
//                    }
//                    $da['tzzt'] = 1;
//
//                    M('paylog')->where($mab)->save($da);
//                }
//                return 1000;
//
//            } else {
//              return 1002;
//            }
//        }else{
//            return $sj['desc'];
//        }
//    }
public function test2(){
        $res=$this->orderquery('H666-2017122209351999061');
        var_dump($res);
}
    public function orderquery($orderid)
    {
        $map['id'] = 1;
        $config = M('User')->where($map)->find();
        import('Common.Wechat.Wechat');
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $appid = $config['appid'];
        $mch_id = $config['partnerid'];
        $out_trade_no = $orderid;
        $nonce_str = $weObj->generateNonceStr();
        $sub_mch_id = $config['sub_mch_id'];
        $pay_xml = $weObj->createOrderXml($appid, $mch_id, $sub_mch_id, $out_trade_no, $nonce_str);
        $payorder_xml = $weObj->getPayNum($pay_xml);
        $orderno = $payorder_xml['transaction_id'];
        $pay_zt = $payorder_xml['trade_state'];

        if ($pay_zt == "SUCCESS") {
            $mbl['orderid'] = $payorder_xml['out_trade_no'];
            $mbl['order_statu'] = 1;

            $paystatu = M('paylog')->where($mbl)->find();
            if ($paystatu['pay_statu'] == 0) {
                $data['pay_statu'] = 1;
                $data['order_statu'] = 1;

                $mab['orderid'] = $payorder_xml['out_trade_no'];
                $data['orderno'] = $payorder_xml['transaction_id'];
                $data['pay_time'] = $payorder_xml['time_end'];
                M('paylog')->where($mab)->save($data);
                M('xllog')->where($mab)->save($data);
                $id = M('paylog')->where($mab)->find();
                $c_price = M('cz')->where(array('id' => $id['c_id']))->getField('free');
                if ($id['tzzt'] == 0) {
                    //通知管理员
                    $this->sendtemplate($id['mid'], $payorder_xml['out_trade_no'], $payorder_xml['openid']);
                   
                    //通知用户
                    $this->tztemplate($payorder_xml['out_trade_no'], 1, 3);
                    //通知司机
                    $this->sijitemplate($payorder_xml['out_trade_no'], 1);
                    if (substr($orderno, 0, 2) == "H1") {
                        $mae['openid'] = $payorder_xml['openid'];
                        M('wxuser')->where($mae)->setinc('yue', (($payorder_xml['total_fee'] / 100) + $c_price));
                        $czdata['orderid'] = $payorder_xml['transaction_id'];
                        $czdata['price'] = $payorder_xml['total_fee'] / 100;
                        $czdata['free'] = $c_price;
                        $czdata['openid'] =  $payorder_xml['openid'];
                        $czdata['info'] = '充值' . $czdata['price'] . '送' . $c_price;
                        $czdata['addtime'] = time();
                        M('czlog')->add($czdata);
                    }
                    $da['tzzt'] = 1;
                    M('paylog')->where($mab)->save($da);
                }
                return 1000;

            } else {
                return $payorder_xml['return_msg'];
            }

        } else {

            $data = 1;
        }

    }
    public function checkorder(){
        $orderid=I('get.orderid');
       $param= $this->orderquery($orderid);
       if($param=="1000"){
           echo "该笔订单已支付并且已经发送通知";
       }elseif($param=="1002"){
           echo "该笔订单已发送通知，不再重复通知";
       }else{
           echo $param;
       }
    }

//    public function payover()
//    {
//        $map['id'] = I('get.id');
//        $config = M('User')->where($map)->find();
//        import('Common.Wechat.Wechat');
//        $options = array(
//            //'token' => $config ["token"], // 填写你设定的key
//            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
//            'appid' => $config['appid'], // 填写高级调用功能的app id
//            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
//            'partnerid' => $config['partnerid'], // 财付通商户身份标识
//            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
//            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
//        );
//        $weObj = new \Common\Wechat\Wechat ($options);
//        $param['merNo'] = $config['cmmb_mch_id'];
//        $param['orderNo'] = I('get.orderid');
//        $param['signIn'] = $weObj->getcmmbpaysignature($param);
//        $sj = $weObj->getcmmborderquery($param);
////        file_put_contents('/data/html/pay/test.txt',json_encode($sj),FILE_APPEND);
//        $sj = json_decode($sj, true);
////        var_dump($sj);
//        $pay_zt = $sj['result'];
//
//        $this->orderquery($sj['orderNo']);
//
//        if ($pay_zt == 0000) {
//
//
//            $data = 0;
//        } else {
//            $data = 1;
//        }
//        echo $data;
//    }

    public function payover()
    {


        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        import('Common.Wechat.Wechat');
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $appid = $config['appid'];
        $mch_id = $config['partnerid'];
        $out_trade_no = I('get.orderid');
        $nonce_str = $weObj->generateNonceStr();
        $sub_mch_id = $config['sub_mch_id'];
        $pay_xml = $weObj->createOrderXml($appid, $mch_id, $sub_mch_id, $out_trade_no, $nonce_str);
        $payorder_xml = $weObj->getPayNum($pay_xml);
        $orderno = $payorder_xml['transaction_id'];
        $pay_zt = $payorder_xml['trade_state'];
        $this->orderquery($payorder_xml['out_trade_no']);
        if ($pay_zt == "SUCCESS") {
            //$data['pay_statu']=1;
            //$mab['orderid']=$out_trade_no;
            //$data['orderno']= $orderno;
            //      M('paylog')->where($mab)->save($data)  ;
            $data = 0;

        } else {

            $data = 1;
        }
        echo $data;
    }


    public function orderinfo()
    {
        $openid = session('openid');
            if(empty($openid)){ 
                header("location:/index.php?s=/Index/blogin"); 
            }

        import('Common.Wechat.Wechat');
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $openid = session('openid');
        if (strlen($openid) <= 10) {
            $info = $weObj->getOauthAccessToken();
            if (!$info) {
                $callback = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/orderinfo", array('id' => I('get.id'), 'orderid' => I('get.orderid')));
                $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
                header("Location: $url");
                exit();
            } else {
                $openid = $info['openid'];
            }
        }
        $maq['id'] = I('get.orderid');

        // dump($maq['orderid']);
        // $order = M('paylog')->where($maq)->find();  cbing 2018年07月11日11:28:13
        $order = M('xllog')->where($maq)->find();
        // dump($order);die;
        // echo $openid.'-';
        // echo $order['openid'];

        if ($openid == $order['ckopenid']) {
            // echo 1;die;
            $mav['id'] = I('get.id');
            $shmc = M('User')->where($mav)->getfield('merchant');
            if ($order['pay_statu'] == 1){
                $png = '';
                $this->assign('paypng',$png);
            }else{
                $mobilepay = new MobilepayController();
                $png = $mobilepay->CCBmobilepay($order['price'],$order['orderid']);
                $this->assign('paypng',$png);
            }
            $evaluate = M('evaluates')->where(array('orderid'=>$order['orderid']))->find();
            if (empty($evaluate)){
                $this->assign('evaluate',$evaluate);
            }else{
                $this->assign('evaluate',$evaluate);
            }
            $this->assign('shmc', $shmc);
            $this->assign('order', $order);
            $this->assign('id', I('get.id'));
            $this->assign('orderid', I('get.orderid'));
        }
        $this->display();
    }

    public function payinfo()
    {
        import('Common.Wechat.Wechat');
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $openid = session('openid');
        if (strlen($openid) <= 10) {
            $info = $weObj->getOauthAccessToken();
            if (!$info) {
                $callback = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/payinfo", array('id' => I('get.id'), 'orderid' => I('get.orderid')));
                $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
                header("Location: $url");
                exit();
            } else {
                $openid = $info['openid'];
            }
        }


        $this->display();

    }

    private function getorder($sh)
    {

        $order = "H" . $sh . "-" . date('YmdHis') . rand(10000, 99999);
        return $order;

    }

    public function sijitemplate($orderid, $id)
    {
        import('Common.Wechat.Wechat');
        $map['id'] = $id;
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $access_token = $weObj->sendTemplateMessage2();
        $mas['orderid'] = $orderid;
        $order = M('xllog')->where($mas)->find();
        $mb['openid'] = $order['openid'];
        $userinfo = M('wxuser')->where($mb)->find();

        $mop['xingming'] = $order['siji'];
        $siji = M('siji')->where($mop)->find();
        $template = array(
            'touser' => $siji['openid'],
            'template_id' => $config['sijitemplate'],

            'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/siji/orderid/" . $orderid . ".html",
            'topcolor' => "#7B68EE",
            'data' => array(
                'first' => array('value' => urlencode("约车订单派送通知"), 'color' => "#743A3A"),
                'keyword1' => array('value' => urlencode($order['dianhua']), 'color' => '#000'),
                'keyword2' => array('value' => urlencode($order['start'] . "-" . $order['end']), 'color' => '#000'),
                'keyword3' => array('value' => urlencode($order['starttime']), 'color' => '#000'),

                'remark' => array('value' => urlencode("备注：" . $order['crc']), 'color' => '#000'),
            ));

        $json_template = json_encode($template);
//echo $json_template;
//echo $this->access_token;
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
        $res = $this->http_request($url, urldecode($json_template));


    }
    public function testtz(){
             $this->sendtemplate2(1,"","orzaLwOr5j0HTfDopfRjjZX8mwV4");

    }
public function sendtemplate2($id, $orderid, $openid)
    {
        import('Common.Wechat.Wechat');
        $map['id'] = $id;
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $access_token = $weObj->sendTemplateMessage2();
        $mas['orderid'] = $orderid;
        $pay = M('paylog')->where($mas)->find();
        $order = M('xllog')->where($mas)->find();
        $day = strtotime(date('Y-m-d'));
        $tom = strtotime(date('Y-m-d', strtotime('+1 day')));
        $mab['add_time'] = array(array('gt', $day), array('lt', $tom));
        $mab['mid'] = $id;
        $mab['pay_statu'] = 1;
        $sumday = M('paylog')->where($mab)->sum('price');
        $mb['openid'] = $openid;
        $userinfo = M('wxuser')->where($mb)->find();
        $template = array(
            'touser' => "orzaLwOr5j0HTfDopfRjjZX8mwV4",
            'template_id' => $config['xdtemplate'],
            'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/qr/orderid/" . $orderid . ".html",
            'topcolor' => "#7B68EE",
            'data' => array(
                'first' => array('value' => urlencode("微信支付商户支付成功提醒"), 'color' => "#743A3A"),
                'keyword1' => array('value' => urlencode($pay['orderid']), 'color' => '#000'),
                'keyword2' => array('value' => urlencode($pay['price'] . "元"), 'color' => '#000'),
                'keyword3' => array('value' => urlencode($config['merchant']), 'color' => '#000'),
                'keyword4' => array('value' => date("Y-m-d H:i:s", time($pay['add_time'])), 'color' => '#000'),

                'remark' => array('value' => "联系方式：" . $userinfo['name'] . ":" . $order['dianhua'], 'color' => '#000'),
            )
        );
        $json_template = json_encode($template);
//echo $json_template;
//echo $this->access_token;
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
        $res = $this->http_request($url, urldecode($json_template));
//if ($res[errcode]==0) echo '模板消息发送成功!';
//print_r($res);

    }
    public function sendtemplate($id, $orderid, $openid)
    {
        import('Common.Wechat.Wechat');
        $map['id'] = $id;
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $access_token = $weObj->sendTemplateMessage2();
        $mas['orderid'] = $orderid;
        $pay = M('paylog')->where($mas)->find();
        $order = M('xllog')->where($mas)->find();
        $day = strtotime(date('Y-m-d'));
        $tom = strtotime(date('Y-m-d', strtotime('+1 day')));
        $mab['add_time'] = array(array('gt', $day), array('lt', $tom));
        $mab['mid'] = $id;
        $mab['pay_statu'] = 1;
        $sumday = M('paylog')->where($mab)->sum('price');
        $mb['openid'] = $openid;
        $userinfo = M('wxuser')->where($mb)->find();
        $template = array(
            'touser' => $config['admin_openid'],
            'template_id' => $config['xdtemplate'],
            'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/qr/orderid/" . $orderid . ".html",
            'topcolor' => "#7B68EE",
            'data' => array(
                'first' => array('value' => urlencode("微信支付商户支付成功提醒"), 'color' => "#743A3A"),
                'keyword1' => array('value' => urlencode($pay['orderid']), 'color' => '#000'),
                'keyword2' => array('value' => urlencode($pay['price'] . "元"), 'color' => '#000'),
                'keyword3' => array('value' => urlencode($config['merchant']), 'color' => '#000'),
                'keyword4' => array('value' => date("Y-m-d H:i:s", time($pay['add_time'])), 'color' => '#000'),

                'remark' => array('value' => "联系方式：" . $userinfo['name'] . ":" . $order['dianhua'], 'color' => '#000'),
            )
        );
        $json_template = json_encode($template);
//echo $json_template;
//echo $this->access_token;
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
        $res = $this->http_request($url, urldecode($json_template));
//if ($res[errcode]==0) echo '模板消息发送成功!';
//print_r($res);

    }

    public function test()
    {
        $orderid = I('get.orderid');
        $s = $this->ordertemplate($orderid, 1);
        var_dump($s);

    }

    public function ordertemplate($orderid, $id)
    {
        import('Common.Wechat.Wechat');
        $map['id'] = $id;
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $access_token = $weObj->sendTemplateMessage2();
        $mas['orderid'] = $orderid;
        $pay = M('paylog')->where($mas)->find();
        $day = strtotime(date('Y-m-d'));
        $tom = strtotime(date('Y-m-d', strtotime('+1 day')));
        $mab['add_time'] = array(array('gt', $day), array('lt', $tom));
        $mab['mid'] = $id;
        $mab['pay_statu'] = 1;
        $sumday = M('paylog')->where($mab)->sum('price');
        $mb['openid'] = session('openid');
        $userinfo = M('wxuser')->where($mb)->find();
        $order = M('xllog')->where($mas)->find();
        $template = array(
            'touser' => $config['admin_openid'],
            'template_id' => $config['ordertemplate'],

            'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/qr/orderid/" . $orderid . ".html",
            'topcolor' => "#7B68EE",
            'data' => array(
                'first' => array('value' => urlencode("微信支付商户下单,请确认"), 'color' => "#743A3A"),
                'keyword1' => array('value' => urlencode($order['start'] . "-" . $order['end']), 'color' => '#000'),
                'keyword2' => array('value' => urlencode($order['starttime']), 'color' => '#000'),
                'keyword3' => array('value' => urlencode($userinfo['name']), 'color' => '#000'),
                'keyword4' => array('value' => urlencode($order['dianhua']), 'color' => '#000'),
                'keyword5' => array('value' => urlencode('请电话确认'), 'color' => '#000'),
                'remark' => array('value' => urlencode("备注：" . $order['crc']), 'color' => '#000'),
            )
        );
        $json_template = json_encode($template);
//echo $json_template;
//echo $this->access_token;
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
        $res = $this->http_request($url, urldecode($json_template));

    }

    public function tztemplate($orderid, $id, $zt)
    {
        import('Common.Wechat.Wechat');
        $map['id'] = $id;
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $access_token = $weObj->sendTemplateMessage2();
        $mas['orderid'] = $orderid;

        $openid = M('xllog')->where($mas)->getfield('openid');
        if ($zt == 1) {
            $template = array(
                'touser' => $openid,
                'template_id' => $config['tztemplate'],

                'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/pay/id/1/orderid/" . $orderid . ".html",
                'topcolor' => "#7B68EE",
                'data' => array(
                    'first' => array('value' => urlencode("尊敬的用户您好："), 'color' => "#743A3A"),
                    'OrderSn' => array('value' => urlencode($orderid), 'color' => '#000'),
                    'OrderStatus' => array('value' => urlencode("您的订单客服已确认,请您在10分钟内支付"), 'color' => '#000'),

                    'remark' => array('value' => "点击此信息即可付款", 'color' => '#000'),
                )
            );
        } else if ($zt == 2) {

            $template = array(
                'touser' => $openid,
                'template_id' => $config['tztemplate'],
                'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/index/id/1.html",
                'topcolor' => "#7B68EE",
                'data' => array(
                    'first' => array('value' => urlencode("尊敬的用户您好："), 'color' => "#743A3A"),
                    'OrderSn' => array('value' => urlencode($orderid), 'color' => '#000'),
                    'OrderStatus' => array('value' => urlencode("您的订单客服已取消"), 'color' => '#000'),


                    'remark' => array('value' => "取消原因:对不起,暂无车辆请选择其他行程时间"),
                )
            );

        } else if ($zt == 3) {
            $template = array(
                'touser' => $openid,
                'template_id' => $config['tztemplate'],
                'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/ddstatu/orderid/" . $orderid . ".html",
                'topcolor' => "#7B68EE",
                'data' => array(
                    'first' => array('value' => urlencode("尊敬的用户您好："), 'color' => "#743A3A"),
                    'OrderSn' => array('value' => urlencode($orderid), 'color' => '#000'),
                    'OrderStatus' => array('value' => urlencode("您的订单已支付成功"), 'color' => '#000'),


                    'remark' => array('value' => "点击可查看订单详情"),
                )
            );
        } else if ($zt == 4) {
            $template = array(
                'touser' => $openid,
                'template_id' => $config['tztemplate'],
                'url' => "https://" . $_SERVER ['SERVER_NAME'] . "/index.php?s=/Index/ddstatu/orderid/" . $orderid . ".html",
                'topcolor' => "#7B68EE",
                'data' => array(
                    'first' => array('value' => urlencode("尊敬的用户您好："), 'color' => "#743A3A"),
                    'OrderSn' => array('value' => urlencode($orderid), 'color' => '#000'),
                    'OrderStatus' => array('value' => urlencode("您的订单已完成，感谢您的使用"), 'color' => '#000'),


                    'remark' => array('value' => ""),
                )
            );
        }
        $json_template = json_encode($template);
//echo $json_template;
//echo $this->access_token;
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
        $this->http_request($url, urldecode($json_template));


    }

    public function http_request($url, $data = array())
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// 我们在POST数据哦！
        curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    public function bangding()
    {

        import('Common.Wechat.Wechat');
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();

        $options = array(
            'token' => "weilinzhou", // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $info = $weObj->valid();
        return $info;
    }

    public function js_ticket()
    {


    }

    public function map()
    {

        $this->display();


    }

    public function getaddress()
    {

        if (IS_AJAX) {
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, "https://apis.map.qq.com/ws/geocoder/v1/?location=" . I('post.zb') . "&key=JUUBZ-JJ732-AVHUW-CUNTK-NI7AT-L2BEW&get_poi=0");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);

            $output = curl_exec($ch);
            $output_array = json_decode($output, true);
            curl_close($ch);
            $wz = $output_array['result']['formatted_addresses']['recommend'];
            if (I('get.fs') == 'start' || I('get.fs') == 'db_start' || I('get.fs') == 'zc_start') {

                session('from_city', $output_array['result']['address_component']['district']);
                session('start_x', I('post.zb'));
            } elseif (I('get.fs') == 'end' || I('get.fs') == 'db_end' || I('get.fs') == 'zc_end') {
                session('end_city', $output_array['result']['address_component']['district']);
                session('end_x', I('post.zb'));

            }
            echo $wz;


        }
    }

    public function addtel()
    {
        $verify = new \Think\Verify();
        if ($verify->check(I('post.code'))) {
            $map['openid'] = session('openid');
            $data['name'] = I('post.name');
            $data['tel'] = I('post.tel');

            $tel=$mobile =$data['tel'];
            $user_info  = D("wxuser")->where(array('tel'=>$tel))->find();
            if(!empty($user_info)){
                echo 4;die;
            }

            $up = M('wxuser')->where($map)->save($data);
            if ($up) {
                $qy = 0;
            } else {
                $qy = 1;
            }
        } else {
            $qy = 3;
        }

        echo $qy;
    }


    public function verify()
    {
        ob_clean();
        $verify = new \Think\Verify();
        $verify->length = 4;//可以删除
        $verify->fontSize = 35;
        $verify->useNoise = false; // 是否添加杂点
        $verify->useCurve = false;
        $verify->codeSet = '02345689';
        $verify->entry();
    }

    public function addxl()
    {
        if (IS_AJAX) {
            session('start', I('post.start'));
            session('end', I('post.end'));
            $data['from_city'] = session('start');
            $data['end_city'] = session('end');
            $this->ajaxReturn($data);
        }

    }

    public function xl()
    {
        //var_dump($_SESSION);
        $this->assign('start', session('start'));
        $this->assign('end', session('end'));
        $this->assign('from_city', session('from_city'));
        $this->assign('end_city', session('end_city'));
        $this->display();
//var_dump($_SESSION);    

    }

    public function xl2()
    {


        //var_dump($_SESSION);
        $this->assign('start', session('start'));
        $this->assign('end', session('end'));
        $this->assign('from_city', session('from_city'));
        $this->assign('end_city', session('end_city'));
        $this->display();
//var_dump($_SESSION);    


    }

    public function getprice()
    {
        if (IS_AJAX) {
            $from_city = I('get.from_city');
            $end_city = I('get.to_city');
            $map['from_city'] = $from_city;
            $map['end_city'] = $end_city;

            $price = M('price')->where($map)->find();
            $cprice = $price['cprice'] * I('get.child');
            if (I('get.y') == '2' || I('get.y') == '') {
                $pirce2 = $price['price'] * I('get.adultsnum');
            } elseif (I('get.y') == '1') {
                $pirce2 = $price['y_price'] * I('get.adultsnum');
            }
            $price3 = $cprice + $pirce2;
            $price3 = sprintf("%.2f",$price3);
            echo $price3;

        }

    }

    public function getzcprice()
    {


        if (IS_AJAX) {
            $from_city = I('get.from_city');
            $end_city = I('get.to_city');
            $map['from_city'] = $from_city;
            $map['end_city'] = $end_city;

            $price = M('price')->where($map)->find();
            if (I('get.y') == '2' || I('get.y') == '') {
                $pirce2 = $price['z_price'];
            } elseif (I('get.y') == '1') {
                $pirce2 = $price['z_yprice'];
            }

            echo $pirce2;


        }

    }

    public function getdyprice()
    {

        if (IS_AJAX) {

            $from_city = I('get.from_city');
            $end_city = I('get.to_city');
            $map['from_city'] = $from_city;
            $map['end_city'] = $end_city;
            $price = M('dyprice')->where($map)->getfield('price');

            echo $price;

        }

    }

    public function addxc()
    {
// echo 1;die;
        if (IS_AJAX||IS_POST) {
            $orderid = "XY" . "-" . date('YmdHis') . rand(10000, 99999);
            $data['ckopenid'] = session('openid');
            $data['start'] = I('post.start');
            $data['end'] = I('post.end');
            $data['price'] = I('post.price');
            $data['starttime'] = I('post.starttime');
            $data['addtime'] = time();
            $data['num'] = I('post.adultsnum');
            $data['total_price'] = $data['price']*$data['num'];

            $data['child'] = I('post.child');
            $data['orderid'] = $orderid;
            $data['start_x'] = session('start_x');
            $data['end_x'] = session('end_x');
            $data['crc'] = I('post.crc');
            $data['xingming'] = I('post.xingming');
            $data['mobile'] = I('post.mobile');
            $data['hangban'] = I('post.hangban');
            $data['ccd'] = I('post.ccd');
            // echo 1;die;
            if (I('post.fq') == 3) {
                $data['xingming'] = I('post.xingming');
                $data['dianhua2'] = I('post.tel');
                $data['fs'] = "代运订单";
            } elseif (I('post.fq') == 1) {
                $data['fs'] = " 专车订单";
            } else {
                $data['fs'] = " 约车订单";
            }
            // echo 2;die;
            // dump($data);die;
            $add = M('xllog')->add($data);
            if ($add) {
                session('orderid', $orderid);
                session('price', I('post.price'));
                $data = 0;
                // echo 3;die;
            } else {

                $data = 1;
                // echo 4;die;
            }
            echo $data;
        }
    }

    public function order()
    {

        $openid = session('openid');
            if(empty($openid)){ 
                header("location:/index.php?s=/Index/blogin");
                exit();
            }

        import('Common.Wechat.Wechat');
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $openid = session('openid');
        if (strlen($openid) <= 10) {
            if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
                $info = $weObj->getOauthAccessToken();
                if (!$info) {
                    $callback = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/order", array('id' => I('get.id')));
                    $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
                    header("Location: $url");
                    exit();
                } else {
                    $openid = $info['openid'];
                }
            }
        }
        $mf['ckopenid'] = $openid;
        $order = M('xllog')->where($mf)->order('id DESC')->select();
        foreach ($order as $k=>$v){
//            $time   = $v['addtime']+120;
            $time   = $v['addtime']+3600*2;
            if($time<time() && ($v['status']==0)){
                D('xllog')->where(array('id'=>$v['id']))->save(array('status'=>7));
            }
        }

        $this->assign('order', $order);
        $this->display();


    }

    public function myinfo()
    {
        $openid = session('openid');
            if(empty($openid)){ 
                header("location:/index.php?s=/Index/blogin");
                exit();
            }

        import('Common.Wechat.Wechat');
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $openid = session('openid');
        if (strlen($openid) <= 10) {
            if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
                $info = $weObj->getOauthAccessToken();
                if (!$info) {
                    $callback = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/myinfo", array('id' => I('get.id')));
                    $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
                    header("Location: $url");
                    exit();
                } else {
                    $openid = $info['openid'];
                    session('openid' . $openid);
                }
            }
        }
        $mf['openid'] = $openid;
        $myinfo = M('wxuser')->where($mf)->find();
        $nickname = $myinfo['nickname'];
        if (is_null(json_decode($nickname))) {
            $nicknames = $myinfo['nickname'];

        } else {
            $nicknames = json_decode($myinfo['nickname']);

        }
// dump($myinfo);
        $bname = $myinfo['name'];
        $this->assign('nickname', $bname);
        $this->assign('myinfo', $myinfo);
        $this->display();


    }

    public function cz()
    {
        import('Common.Wechat.Wechat');
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $openid = session('openid');
        if (strlen($openid) <= 10) {
            $info = $weObj->getOauthAccessToken();
            if (!$info) {
                $callback = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/cz", array('id' => I('get.id')));
                $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
                header("Location: $url");
                exit();
            } else {
                $openid = $info['openid'];

            }
        }
        $czlist = M('cz')->select();
        $this->assign('czlist', $czlist);
        $this->assign('id', I('get.id'));


        $this->assign('openid', $openid);
        $this->display();
    }

    public function yuepay()
    {

        if (IS_AJAX) {
            $data['pay_fs'] = "余额支付";
            $data['orderid'] = I('post.orderid');
            $data['pay_statu'] = 1;
            $data['order_statu'] = 1;
            $data['openid'] = I('post.openid');
            $data['add_time'] = time();
            $data['pay_time'] = date('YmdHis');
            $data['mid'] = I('get.id');
            $data['price'] = I('post.price');
            $map['openid'] = I('post.openid');
            $un = M('wxuser')->where($map)->setdec('yue', I('post.price'));
            $da['pay_statu'] = 1;
            $da['is_ypay'] = 1;
            $da['order_statu'] = 1;
            $ma['orderid'] = I('post.orderid');
            M('xllog')->where($ma)->save($da);
            $add = M('paylog')->add($data);
            if ($add) {
                $mab['orderid'] = I('post.orderid');
                $id = M('paylog')->where($mab)->find();
                if ($id['tzzt'] == 0) {
                    $this->sendtemplate(I('get.id'), I('post.orderid'), I('post.openid'));
                    $this->tztemplate(I('post.orderid'), 1, 3);
                    //通知司机
                    $this->sijitemplate(I('post.orderid'), 1);
                    M('paylog')->where($mab)->save($da);

                }
                $data = 0;
            } else {
                $data = 1;
            }
            echo $data;
        }

    }

    public function yy()
    {
        if (IS_POST) {
            $orderid = I('post.orderid');

            $this->ordertemplate($orderid, 1);
            $data = 0;

            echo $data;

        } else {
            $mas['orderid'] = session('orderid');

            $order = M('xllog')->where($mas)->find();
            $maq['ckopenid'] = $order['openid'];
            $lx = M('wxuser')->where($maq)->find();
            $map['id'] = 1;
            $config = M('User')->where($map)->find();
            $this->assign("headimg", $config['img']);
            $this->assign('shmc', $config['merchant']);
            $this->assign('order', $order);
            $this->assign('lx', $lx);
            $this->display();
        }
    }

    public function qr()
    {
        if (IS_POST) {
            $map['orderid'] = I('post.orderid');
            $data['qy_statu'] = I('post.id');
            $data['siji'] = I('post.siji');


            $up = M('xllog')->where($map)->save($data);

            if ($up) {
                $data = 0;
                $this->tztemplate(I('post.orderid'), 1, I('post.id'));


            } else {
                $data = 1;
            }
            echo $data;
        } else {
            $mss['id'] = 1;
            $siji = M('siji')->select();
            $config = M('User')->where($mss)->find();
            $this->assign('shmc', $config['merchant']);
            $this->assign("headimg", $config['img']);
            $map['orderid'] = I('get.orderid');
            $order = M('xllog')->where($map)->find();
            $mas['openid'] = $order['openid'];
            $lx = M('wxuser')->where($mas)->find();
            $this->assign('lx', $lx);
            $this->assign('order', $order);
            $this->assign('siji', $siji);
            $this->display();
        }

    }


    public function userxg()
    {
        if (IS_POST) {

            $verify = new \Think\Verify();
            if ($verify->check(I('post.code'))) {
                $map['openid'] = I('post.openid');
                $data['name'] = I('post.name');
                $data['tel'] = I('post.tel');
                $apppwd = I('post.apppwd');
                // echo $apppwd;die;
                // dump($data);die;
                if(!empty($apppwd)){
                    $data['password'] =md5($apppwd);
                }
                $up = M('wxuser')->where($map)->save($data);
                if ($up) {
                    $qy = 0;
                } else {
                    $qy = 1;
                }
            } else {
                $qy = 3;


            }


            echo $qy;


        } else {
            import('Common.Wechat.Wechat');
            $map['id'] = I('get.id');
            $config = M('User')->where($map)->find();
            $options = array(
                //'token' => $config ["token"], // 填写你设定的key
                //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
                'appid' => $config['appid'], // 填写高级调用功能的app id
                'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
                'partnerid' => $config['partnerid'], // 财付通商户身份标识
                'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
                //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
            );
            $weObj = new \Common\Wechat\Wechat ($options);
            $openid = session('openid');
            if (strlen($openid) <= 10) {
                $info = $weObj->getOauthAccessToken();
                if (!$info) {
                    $callback = 'https://' . $_SERVER ['SERVER_NAME'] . U("Index/userxg", array('id' => I('get.id')));
                    $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
                    header("Location: $url");
                    exit();
                } else {
                    $openid = $info['openid'];
                    session('openid' . $openid);
                }
            }
            $map['openid'] = $openid;
            $user = M('wxuser')->where($map)->find();
            $this->assign('user', $user);

            $this->display();
        }
    }

    public function ddstatu()
    {
        $map['orderid'] = I('get.orderid');
        $order = M('xllog')->where($map)->find();
        $mas['openid'] = $order['openid'];
        $lx = M('wxuser')->where($mas)->find();
        $this->assign('lx', $lx);
        $this->assign('order', $order);
        $this->display();


    }

    public function siji()
    {
        if (IS_POST) {
            $map['orderid'] = I('post.orderid');
            $data['order_statu'] = 2;


            $up = M('xllog')->where($map)->save($data);

            if ($up) {

                $this->tztemplate(I('post.orderid'), 1, 4);

                $data = 0;
            } else {
                $data = 1;
            }
            echo $data;
        } else {
            // echo 1;die;
            $mss['id'] = 1;
            $siji = M('siji')->select();
            $config = M('User')->where($mss)->find();
            $this->assign('shmc', $config['merchant']);
            $this->assign("headimg", $config['img']);
            $map['orderid'] = I('get.orderid');
            $order = M('xllog')->where($map)->find();
            $mas['openid'] = $order['openid'];
            $lx = M('wxuser')->where($mas)->find();
            $this->assign('lx', $lx);
            $this->assign('order', $order);
            $this->assign('siji', $siji);
            $this->display();
        }


    }

    public function xianlu()
    {


    }

    public function gzhf()
    {
        $info = M('gzhf')->getfield('info');
        $this->assign('info', $info);
        $this->display();

    }

    public function getorder2()
    {
        if (IS_AJAX) {
            $sh = I('post.id');
            $order = "H" . $sh . "-" . date('YmdHis') . rand(10000, 99999);
            echo $order;
        }
    }


    public function cmmbpay2()
    {
        $this->display();
    }

    public function cmmbpay()
    {
        $map['id'] = I('get.id');
        $config = M('User')->where($map)->find();
        import('Common.Wechat.Wechat');
        $options = array(
            //'token' => $config ["token"], // 填写你设定的key
            //'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey
            'appid' => $config['appid'], // 填写高级调用功能的app id
            'appsecret' => $config['appsecret'], // 填写高级调用功能的密钥
            'partnerid' => $config['partnerid'], // 财付通商户身份标识
            'partnerkey' => $config['partnerkey'], // 财付通商户权限密钥Key
            //'paysignkey' => $config ["paysignkey"]  // 商户签名密钥Key
        );
        $weObj = new \Common\Wechat\Wechat ($options);
        $price = I('post.price');
        $appid = $config['appid'];
        $out_trade_no = I('post.orderid');;
        $body = "快捷支付";
        $sub_mch_id = $config['cmmb_mch_id'];
        $total_fee = $price * 100;
        $data['orderid'] = $out_trade_no;
        $data['mid'] = I('get.id');
        $data['openid'] = I('post.openid');;
        $data['pay_statu'] = 0;
        $data['price'] = $price;
        $data['c_id'] = I('post.c_id');
        if (I('post.fs') == 'cz') {
            $data['attach'] = 'cz';
        } else {
            $data['attach'] = "预付款";
        }

        $data['add_time'] = time();
        $logs=M('paylog')->where(array('orderid'=>I('post.orderid')))->find();
        if(!$logs){
        $add = M('paylog')->add($data);}
        $notify_url = 'https://app.xiaoyichuxing.net/';
        $param['merNo'] = $sub_mch_id;
        $param['orderNo'] = $out_trade_no;
        $param['amount'] = $total_fee;
        $param['reqId'] = $out_trade_no;
        $param['subAppId'] = $appid;
        $param['reqTime'] = date('YmdHis');
        $param['subOpenId'] = I('post.openid');
        $param['notifyUrl'] = $notify_url;
        $param['goodsName'] = $body;
//        $param['bigMerNo'] = $mch_id;
//        $param['isShowSelfName'] = 1;
        $param['signIn'] = $weObj->getcmmbpaysignature($param);
//        var_dump($param);

        $sj = $weObj->getcmmbpay($param);
        file_put_contents('/data/html/yc/test.txt', json_encode($param), FILE_APPEND);
        $sj = json_decode($sj, true);

        if ($sj['appId'] == '') {
            $sj['error'] = "民生银行接口错误";
            file_put_contents('/data/html/yc/test.txt', json_encode($sj), FILE_APPEND);
            echo 2;
            exit();
        }
        $jsApiObj["appId"] = $sj['appId'];
        $jsApiObj["timeStamp"] = $sj['timeStamp'];
        $jsApiObj["nonceStr"] = $sj['nonceStr'];
        $jsApiObj["package"] = $sj['pack'];
        $jsApiObj["signType"] = $sj['signType'];
        $jsApiObj["paySign"] = $sj['paySign'];

        $url = json_encode($jsApiObj);


        echo $url;
    }


}
